<%--
  Created by IntelliJ IDEA.
  User: DELL
  Date: 2022/9/24
  Time: 10:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="page/head.jsp" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="col-md-12 text-center">
                <form class="form-inline" id="searchForm" method="post" action="/emp?method=getAll">
                    <div class="form-group">
                        <label for="exampleInputName2">员工名</label>
                        <input type="text" class="form-control" id="exampleInputName2" name="ename" placeholder="员工名">
                    </div>
                    <div class="form-group">
                        开始
                        <input type="date" class="form-control" name="start">
                        至
                        <input type="date" class="form-control" name="end">
                    </div>
                    <div class="form-group">
                        <label class="radio-inline">
                            <input type="radio" name="esex" id="inlineRadio1" value="男"> 男
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="esex" id="inlineRadio2" value="女"> 女
                        </label>
                    </div>
                    <button type="submit" class="btn btn-default">搜索</button>
                </form>
            </div>
        </div>

        <div class="row">
            <div class="col-md-1 col-md-offset-2">
                <a href="/addEmp.jsp" class="btn btn-info" role="button">新增</a>
            </div>
        </div>

        <div class="row">
            <div class="col-md-8 col-md-offset-2">
                <table class="table table-bordered table-hover">
                    <thead>
                    <tr>
                        <th>员工编码</th>
                        <th>员工姓名</th>
                        <th>员工性别</th>
                        <th>员工工资</th>
                        <th>员工密码</th>
                        <th>员工部门</th>
                        <th>员工出生日期</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach items="${empList.list}" var="emp">
                        <tr>
                            <td>${emp.eno}</td>
                            <td>${emp.ename}</td>
                            <td>${emp.esex}</td>
                            <td>${emp.salary}</td>
                            <td>${emp.pwd}</td>
                            <td>${emp.d.dname}</td>
                            <td><fmt:formatDate value="${emp.bornDate}" pattern="yyyy-MM-dd" ></fmt:formatDate> </td>
                            <td>
                                <button type="button" onclick="getEmp(${emp.eno})" class="btn btn-warning">修改</button>
                                <button type="button" onclick="del(${emp.eno})" class="btn btn-danger">删除</button>
                            </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                    <tfoot>
                    <tr align="center">
                        <td colspan="8">
                            <nav aria-label="Page navigation">
                                <ul class="pagination">
                                    <li>
                                        <a href="/emp?method=getAll&pageNum=1" aria-label="Previous">
                                            <span aria-hidden="true">首页</span>
                                        </a>
                                    </li>
                                    <li>
                                        <a href="/emp?method=getAll&pageNum=${empList.prePage}" aria-label="Previous">
                                            <span aria-hidden="true">&laquo;</span>
                                        </a>
                                    </li>
                                    <c:forEach var="i" items="${empList.navigatepageNums}">
                                        <li ${empList.pageNum==i?"class='active'":""}><a href="/emp?method=getAll&pageNum=${i}">${i}</a></li>
                                    </c:forEach>
                                    <li>
                                        <a href="/emp?method=getAll&pageNum=${empList.nextPage}" aria-label="Next">
                                            <span aria-hidden="true">&raquo;</span>
                                        </a>
                                    </li>
                                    <li>
                                        <a href="/emp?method=getAll&pageNum=${empList.pages}" aria-label="Next">
                                            <span aria-hidden="true">尾页</span>
                                        </a>
                                    </li>
                                </ul>
                            </nav>
                        </td>
                    </tr>
                    </tfoot>
                </table>
            </div>
        </div>
    </div>
<script>
    function getEmp(eno) {
        location.href = "/emp?method=getEmpByEno&eno=" + eno
    }

    function del(eno) {
        if (confirm("是否要删除？")) {
            $.ajax({
                url:"/emp?method=deleteEmp&eno=" + eno,
                type:"get",
                success:function (result) {
                    if (result == 1) {
                        alert("删除成功");
                        location.reload()
                    }else{
                        alert("删除失败");
                    }
                }
            })
        }
    }
</script>
</body>
</html>
